]> git.r.bdr.sh - rbdr/map/blame_incremental - Map/Presentation/Base Components/MapRender/MapAxes.swift
Update to support notes + new style
[rbdr/map] / Map / Presentation / Base Components / MapRender / MapAxes.swift
... / ...
CommitLineData
1import SwiftUI
2
3struct MapAxes: View {
4
5 let mapSize: CGSize
6 let lineWidth: CGFloat
7 let evolution: Stage
8 let stages: [CGFloat]
9 let stageHeight = CGFloat(100.0)
10 let padding = CGFloat(5.0)
11
12 var body: some View {
13 ZStack(alignment: .topLeading) {
14
15 // Axis Lines
16 Path { path in
17 path.move(to: CGPoint(x: 0, y: 0))
18 path.addLine(to: CGPoint(x: 0, y: mapSize.height))
19 path.addLine(to: CGPoint(x: mapSize.width, y: mapSize.height))
20 path.move(to: CGPoint(x: mapSize.width, y: mapSize.height))
21 path.closeSubpath()
22 }.stroke(Color.map.axisColor, lineWidth: lineWidth * 2)
23
24 // Y Labels
25 Text("Visible").font(.theme.axisLabel).foregroundColor(.map.labelColor).rotationEffect(Angle(degrees: -90.0))
26 .offset(CGSize(width: -35.0, height: 0.0))
27 Text("Invisible").font(.theme.axisLabel).foregroundColor(.map.labelColor).rotationEffect(Angle(degrees: -90.0))
28 .offset(CGSize(width: -40.0, height: mapSize.height - 20))
29
30 // X Labels
31
32 Text("Uncharted")
33 .font(.theme.axisLabel)
34 .foregroundColor(.map.labelColor)
35 .frame(width: mapSize.width / 4, height: stageHeight / 2.0, alignment: .topLeading)
36 .offset(CGSize(width: 0.0, height: -stageHeight / 4.0))
37 Text("Industrialised")
38 .font(.theme.axisLabel)
39 .foregroundColor(.map.labelColor)
40 .frame(width: mapSize.width / 4, height: stageHeight / 2.0, alignment: .topLeading)
41 .offset(CGSize(width: mapSize.width - 100.0, height: -stageHeight / 4.0))
42
43 Text(evolution.i)
44 .font(.theme.axisLabel)
45 .foregroundColor(.map.labelColor)
46 .frame(width: w(stages[0]), height: stageHeight, alignment: .topLeading)
47 .offset(CGSize(width: 0.0, height: mapSize.height + padding))
48
49 Text(evolution.ii)
50 .font(.theme.axisLabel)
51 .foregroundColor(.map.labelColor)
52 .frame(width: w(stages[1]) - w(stages[0]), height: stageHeight, alignment: .topLeading)
53 .offset(CGSize(width: w(stages[0]), height: mapSize.height + padding))
54
55 Text(evolution.iii)
56 .font(.theme.axisLabel)
57 .foregroundColor(.map.labelColor)
58 .frame(width: w(stages[2]) - w(stages[1]), height: stageHeight, alignment: .topLeading)
59 .offset(CGSize(width: w(stages[1]), height: mapSize.height + padding))
60
61 Text(evolution.iv)
62 .font(.theme.axisLabel)
63 .foregroundColor(.map.labelColor)
64 .frame(width: mapSize.width - w(stages[2]), height: stageHeight, alignment: .topLeading)
65 .offset(CGSize(width: w(stages[2]), height: mapSize.height + padding))
66 }
67 }
68
69 func w(_ dimension: CGFloat) -> CGFloat {
70 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
71 }
72}
73
74struct MapAxes_Previews: PreviewProvider {
75 static var previews: some View {
76 MapAxes(
77 mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(1.0),
78 evolution: Stage.stages(.general), stages: [25.0, 50.0, 75.0]
79 ).padding(50.0)
80 }
81}